package codingforgreat.lchot150;

public class Lc007 {
    public int reverse(int x) {
        boolean isB = ((x >>> 31) & 1) == 1;
        if(!isB){
            x = -x;
        }
        int m = Integer.MIN_VALUE / 10;
        int n = Integer.MIN_VALUE % 10;
        int res = 0;
        while(x != 0){
            if (res < m || (res == m && x % 10 < n)) {
                return 0;
            }
            res = res * 10 + (x % 10);
            x /= 10;
        }
        return isB ? res : -res;

    }
}
